cmake_minimum_required(VERSION 3.10)

project(lvgl)

set(lvgl_sources
  src/lv_gpu/lv_gpu_v2d.c
  src/lv_core/lv_group.c
  src/lv_core/lv_indev.c
  src/lv_core/lv_disp.c
  src/lv_core/lv_obj.c
  src/lv_core/lv_refr.c
  src/lv_core/lv_style.c
  src/lv_misc/lv_debug.c
  src/lv_draw/lv_draw_rect.c
  src/lv_draw/lv_draw_label.c
  src/lv_draw/lv_draw_line.c
  src/lv_draw/lv_draw_img.c
  src/lv_draw/lv_draw_arc.c
  src/lv_draw/lv_draw_triangle.c
  src/lv_draw/lv_draw_blend.c
  src/lv_draw/lv_draw_mask.c
  src/lv_draw/lv_img_decoder.c
  src/lv_draw/lv_img_cache.c
  src/lv_draw/lv_img_buf.c
  src/lv_draw/lv_draw_gif_player.c
  src/lv_draw/lv_draw_img_png_decoder.c
  src/lv_draw/lv_draw_img_jpeg_decoder.c
  src/lv_draw/lv_draw_img_png8_decoder.c
  src/lv_font/lv_font.c
  src/lv_font/lv_font_loader.c
  src/lv_font/lv_font_fmt_txt.c
  src/lv_font/lv_freetype.c
  src/lv_font/lv_font_montserrat_12.c
  src/lv_font/lv_font_montserrat_12_subpx.c
  src/lv_font/lv_font_montserrat_14.c
  src/lv_font/lv_font_montserrat_16.c
  src/lv_font/lv_font_montserrat_18.c
  src/lv_font/lv_font_montserrat_20.c
  src/lv_font/lv_font_montserrat_22.c
  src/lv_font/lv_font_montserrat_24.c
  src/lv_font/lv_font_montserrat_26.c
  src/lv_font/lv_font_montserrat_28.c
  src/lv_font/lv_font_montserrat_28_compressed.c
  src/lv_font/lv_font_montserrat_30.c
  src/lv_font/lv_font_montserrat_32.c
  src/lv_font/lv_font_montserrat_34.c
  src/lv_font/lv_font_montserrat_36.c
  src/lv_font/lv_font_montserrat_38.c
  src/lv_font/lv_font_montserrat_40.c
  src/lv_font/lv_font_montserrat_42.c
  src/lv_font/lv_font_montserrat_44.c
  src/lv_font/lv_font_montserrat_46.c
  src/lv_font/lv_font_montserrat_48.c
  src/lv_font/lv_font_simsun_16_cjk.c
  src/lv_font/lv_font_unscii_8.c
  src/lv_misc/lv_area.c
  src/lv_misc/lv_task.c
  src/lv_misc/lv_fs.c
  src/lv_misc/lv_anim.c
  src/lv_misc/lv_mem.c
  src/lv_misc/lv_ll.c
  src/lv_misc/lv_color.c
  src/lv_misc/lv_txt.c
  src/lv_misc/lv_math.c
  src/lv_misc/lv_log.c
  src/lv_misc/lv_gc.c
  src/lv_misc/lv_utils.c
  src/lv_misc/lv_async.c
  src/lv_misc/lv_printf.c
  src/lv_misc/lv_bidi.c
  src/lv_misc/lv_flashfs.c
  src/lv_misc/lv_romfs.c
  src/lv_misc/lv_qrcode.c
  src/lv_misc/lv_barcode.c
  src/lv_misc/lv_pcfs.c
  src/lv_misc/lv_sdfs.c
  src/lv_misc/lv_txt_ap.c
  src/lv_widgets/lv_arc.c
  src/lv_widgets/lv_bar.c
  src/lv_widgets/lv_btn.c
  src/lv_widgets/lv_btnmatrix.c
  src/lv_widgets/lv_calendar.c
  src/lv_widgets/lv_canvas.c
  src/lv_widgets/lv_chart.c
  src/lv_widgets/lv_checkbox.c
  src/lv_widgets/lv_cont.c
  src/lv_widgets/lv_cpicker.c
  src/lv_widgets/lv_dropdown.c
  src/lv_widgets/lv_gauge.c
  src/lv_widgets/lv_imgbtn.c
  src/lv_widgets/lv_img.c
  src/lv_widgets/lv_keyboard.c
  src/lv_widgets/lv_label.c
  src/lv_widgets/lv_led.c
  src/lv_widgets/lv_line.c
  src/lv_widgets/lv_linemeter.c
  src/lv_widgets/lv_list.c
  src/lv_widgets/lv_msgbox.c
  src/lv_widgets/lv_objmask.c
  src/lv_widgets/lv_objx_templ.c
  src/lv_widgets/lv_page.c
  src/lv_widgets/lv_roller.c
  src/lv_widgets/lv_slider.c
  src/lv_widgets/lv_spinbox.c
  src/lv_widgets/lv_spinner.c
  src/lv_widgets/lv_switch.c
  src/lv_widgets/lv_table.c
  src/lv_widgets/lv_tabview.c
  src/lv_widgets/lv_textarea.c
  src/lv_widgets/lv_tileview.c
  src/lv_widgets/lv_win.c
  src/lv_themes/lv_theme.c
  src/lv_themes/lv_theme_empty.c
  src/lv_themes/lv_theme_material.c
  src/lv_themes/lv_theme_mono.c
  src/lv_themes/lv_theme_template.c
  #src/lv_themes/lv_theme_simple.c  # for lv_phone project
)

set(lvgl_hal
  hal/hal.c
  hal/hal_bt.c
  hal/hal_ble_fmp.c
  hal/hal_ble_hrp.c
  hal/hal_ble.c
  hal/hal_wlan.c
  hal/hal_wlan_pc.c
  hal/realtek/dataTrans_hci.c
  hal/realtek/dataTrans_queue.c
  hal/realtek/dataTrans_uart.c
  hal/realtek/hci_app.c
  hal/realtek/hci_cmd.c
  hal/realtek/rtl8763bf_task.c
  hal/realtek/headset.c
  hal/realtek/localplay.c
  hal/realtek/check_package_id.c
  hal/realtek/test_pcm.c
  hal/dm/cJSON.c
  hal/dm/aes.c
  hal/dm/dm_base64.c
  hal/dm/dm_interface.c
  hal/dm/dm_main.c
  hal/dm/telecom_dm.c
  hal/dm/dm_cmid.c
  hal/hal_http.c
  hal/md5/hal_md5.c
  hal/md5/hal_md5hl.c
  src/lv_hal/lv_hal_disp.c
  src/lv_hal/lv_hal_indev.c
  src/lv_hal/lv_hal_tick.c
)

add_library(lvgl_hal STATIC ${lvgl_hal})
target_include_directories(lvgl_hal INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(lvgl_hal PRIVATE ${PRODUCT_CONFIG_DIR}
    ${LVGL_DIR} ${LVGL_DIR}/lvgl
    ${LVGL_DIR}/lvgl/hal/realtek/inc
    ${LVGL_DIR}/lvgl/hal/bt_inc
    ${EXTERNAL_DIR}/third-party-libs/curl
)

# Add the static library
add_library(lvgl STATIC ${bt_firmware_h_file} ${lvgl_sources})
target_include_directories(lvgl INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(lvgl PRIVATE ${PRODUCT_CONFIG_DIR} ${LVGL_DIR}
    ${LVGL_DIR}/lvgl
    ${EXTERNAL_DIR}/libpng
    ${EXTERNAL_DIR}/libqrencode
    ${EXTERNAL_DIR}/code128
    ${EXTERNAL_DIR}/third-party-libs/freetype/include
)
if(DEFINED SDL2_INCLUDE_DIRS)
    target_include_directories(lvgl PRIVATE ${SDL2_INCLUDE_DIRS})
endif()

target_link_libraries(lvgl libpng libqrencode code128 freetype)

# Add the static library for sram
set(lvgl_sources_ram
  src/lv_misc/lv_tsrb.c
)
add_library(lvgl_ram STATIC ${lvgl_sources_ram})
target_include_directories(lvgl_ram INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(lvgl_ram PRIVATE ${PRODUCT_CONFIG_DIR} ${LVGL_DIR}
    ${LVGL_DIR}/lvgl
)

if(${HAS_JPEG_LIB} STREQUAL "FALSE")
    target_include_directories(lvgl PRIVATE ${PRODUCT_CONFIG_DIR} ${LVGL_DIR}
	${EXTERNAL_DIR}/libjpeg-turbo
    )
    target_link_libraries(lvgl libjpeg)
endif()

if("x${CMAKE_C_COMPILER_ID}" STREQUAL "xARMCC")
  target_compile_options(lvgl PRIVATE "--diag-suppress=1,111,546,1293")
endif()
